﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace CommonLibrary
{
    public static class MonitorMsgHelperDemo
    {
        private static bool result = false;
        public static void RunDemo()
        {
            MonitorMsgHelper helper = new MonitorMsgHelper();
            helper.StartMonitor(1, 10, Function, Validation);
            new Task(() =>
            {
                Console.WriteLine($"{DateTime.Now.ToString()}: Start Thread(Id: {Thread.CurrentThread.ManagedThreadId})");
                Thread.Sleep(6000);
                helper.StopMonitor();
                //Console.WriteLine($"{DateTime.Now.ToString()}: Begin Changed Value");
                result = true;
            }).Start();
            while (!Console.ReadLine().Equals("exit"))
            {
                Console.WriteLine("Error Input");
            }
        }

        private static void Function()
        {
            Console.WriteLine($"{DateTime.Now.ToString()}: Begin Try a Method invoke");
        }

        private static bool Validation()
        {
            return result;
        }
    }
}
